import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenTwoRouter } from '../Common/options'
import { OrganizationIdentityLevel } from '../Common/Conversion'

export const Meterage = async ({ url, OptionsEvent, Permission, actionRef }) => {
    const OrgList = await OrganizationIdentityLevel(3)
    let data = {
        type: '进度管控',
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'createTime@desc' },
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission.findIndex(v => v.uuid === '6eb0d1f0-9930-47c8-8bdc-3c8dd74bec99') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                ...commonTableList.tableName,
                hideInAdded: true,
                hideInSearch: true,
                hideInModify: true,
                render: (_, { organizationUuid, yearMonth }) => {
                    const [year, month] = yearMonth.split('-')
                    return (
                        <div>
                            {OrgList[organizationUuid]}
                            {year}年{month}月 计量
                        </div>
                    )
                },
                width: 400,
            },
            {
                dataIndex: 'organizationUuid',
                title: '组织机构',
                valueType: 'select',
                valueEnum: OrgList,
                ellipsis: true,
                width: 300,
                rules: true,
            },
            {
                dataIndex: 'yearMonth',
                title: '年月',
                valueType: 'Date',
                hideInSearch: true,
                picker: 'month',
                showDate: true,
                rules: true,
                width: 150,
            },
            commonTableList.remark,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    // const { uuid } = record
                    return [
                        Permission.findIndex(v => v.uuid === 'e85e65d3-6325-4189-8a18-2d38f9e2a401') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        <OpenTwoRouter
                            key="TwoTwo"
                            title="附件"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'MeterageAttachment',
                                Permission,
                                actionRef,
                                oneData: record,
                                header: data.columns,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === 'e3ddb12e-e5f4-4141-8a7a-ac3fb3775a1f') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
